package com.jy.api.vo.clerk;

import com.jy.api.domain.ProductType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by lihu on 2018/3/24.
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SaleInfoVo {


    private int target;

    private Double upMonthTotal = 0d;

    private Double sameMonthTotal = 0d;


    private List<ClassifyCount> countList = new ArrayList<>();


    public void accuracy() {
        sameMonthTotal = Math.rint(sameMonthTotal * 100) / 100d;
    }

    public void setClassifyCount(Map<String, Object> map, ProductType type) {
        Double amount = Double.parseDouble(map.get("amount").toString());
        amount = Math.rint(amount * 100) / 100d;
        sameMonthTotal += amount;
        ClassifyCount classifyCount = new ClassifyCount();
        classifyCount.setTypeName(type != null ? type.getName() : "");
        classifyCount.setQty(Integer.parseInt(map.get("quantity").toString()));
        classifyCount.setAmount(amount);
        countList.add(classifyCount);
    }

    public SaleInfoVo(Double upMonthTotal) {

        this.upMonthTotal = Math.rint(upMonthTotal * 100) / 100d;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ClassifyCount {


        private String typeName;

        private int qty;

        private Double amount;


    }
}
